const app = require("./app");
const mongoose = require("mongoose");
const config = require("./config");

// 连接数据库
mongoose
  .connect(config.mongoUri, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
  .then(() => {
    console.log("数据库连接成功");
  })
  .catch((err) => {
    console.error("数据库连接失败:", err);
    process.exit(1);
  });

// 启动服务器
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
  console.log(`服务器运行在端口 ${PORT}`);
  console.log("路由已注册：");
  console.log(" - POST   /api/ratings/:torrentId");
  console.log(" - GET    /api/ratings/torrent/:torrentId");
  console.log(" - GET    /api/ratings/user/:userId");
  console.log(" - GET    /api/ratings/torrent/:torrentId/user/:userId");
  console.log(" - GET    /api/ratings/torrent/:torrentId/stats");
  console.log(" - DELETE /api/ratings/:ratingId");
});
